jQuery(document).on("pageinit", "[data-role='page'][data-pagetype='prodcommentadd']", function(event) {
    var page = jQuery(this);
    var comment = page.find("textarea#textarea");
    var prodid = get_url_params(page.jqmData("url"), "prodid");

    page.find("a.submit").click(function(event) {
        if (jQuery.trim(comment.val())) {
            $.ajax({
                type: "POST",
                url: URL_ACTION_PUBLISH_COMMENT,
                data: {
                    content: jQuery.trim(comment.val()),
                    product: prodid,
                },

                success: function(msg) {
                    $.mobile.changePage(URL_VIEW_PROD_CONTENT, {type: "get", data: {id: prodid},  transition: "slide", reverse: false, changeHash: true });
                },

                error: function(req, status, error) {
                    errmsg = page.find("div.errmsg");
                    errmsg.find("p").html("您还没有登录！");
                    errmsg.popup("open");
                }
            });
        } else {
            errmsg = page.find("div.errmsg");
            errmsg.find("p").html("评论不能为空！");
            errmsg.popup("open");
        }
    });
});

